"""
Voice selector module for HeyGen video generator.
Handles voice selection for avatar videos.
"""

import sys
import os

# Add the project root directory to the Python path
sys.path.append(os.path.dirname(os.path.dirname(os.path.dirname(os.path.abspath(__file__)))))

from playwright.async_api import Page

# Use absolute import for avatar_data
sys.path.append(os.path.dirname(os.path.dirname(os.path.dirname(os.path.abspath(__file__)))))
import avatar_data


class VoiceSelector:
    """
    Handles voice selection for HeyGen avatar videos.
    """
    
    async def select_voice(self, page: Page, avatar_name: str) -> bool:
        """
        Select voice for the avatar video.
        
        Args:
            page (Page): Playwright page instance
            avatar_name (str): Name of the avatar
            
        Returns:
            bool: True if voice selected successfully, False otherwise
        """
        try:
            # Click Select voice button
            await page.locator('iconpark-icon[name="audio"]').click()
            print("Clicked Select voice")
            
            # Wait for dialog to appear
            await page.wait_for_timeout(2000)
            
            await page.get_by_text('Voice Clone').nth(0).click()
            
            # Wait for selection to complete
            await page.wait_for_timeout(2000)
            return True
        except Exception as e:
            print(f"Failed to select voice: {e}")
            return False